<?php
/**
 * Created by PhpStorm.
 * User: yiduan
 * Date: 2018/11/21 0021
 * Time: 17:46
 */

namespace app\cmd\command;

use think\cache\driver\Redis;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
use think\Exception;
use think\Log;
use think\model\Merge;
use think\Upload;
use think\console\input\Argument;

class Common extends Command
{

    protected $args;
    protected $input;
    protected $output;
    protected $redis;

    protected function configure()
    {
        parent::configure();
    }

    protected function execute(Input $input, Output $output)
    {
        set_time_limit(0);
        $this->kaiguan();
        $this->input = $input;
        $this->output = $output;
        $this->redis = new Redis(config('redis'));
        $this->args = $input->getArguments();
    }

    protected function arg($key = '', $default = 's1233#df')
    {
        if (!$key) {
            return $this->args;
        }
        if (isset($this->args[$key])) {
            return $this->args[$key];
        }
        if ($default != 's1233#df') {
            return $default;
        }
        return 0;
    }

    protected function kaiguan()
    {
        $path = 'config/kai_guan.conf';
        if (file_exists($path)) {
            $data = file_get_contents($path);
            if ($data != 'on') {
                $this->output->writeln("配置开关为关闭状态！" . $path);
                exit;
            }
        } else {
            $this->output->writeln("请配置开关信息" . $path);
            exit;
        }
    }

    protected function pipiName($itemid)
    {
        return md5('yoo' . $itemid . 'tv');
    }

    function numToStr($num)
    {
        $result = "";
        if (stripos($num, 'e') === false) {
            return $num;
        }
        while ($num > 0) {
            $v = $num - floor($num / 10) * 10;
            $num = floor($num / 10);
            $result = $v . $result;
        }
        return $result;
    }

    protected function removeEmoji($text) {
        $clean_text = "";
        // Match Emoticons
        $regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
        $clean_text = preg_replace($regexEmoticons, '', $text);
        // Match Miscellaneous Symbols and Pictographs
        $regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u';
        $clean_text = preg_replace($regexSymbols, '', $clean_text);
        // Match Transport And Map Symbols
        $regexTransport = '/[\x{1F680}-\x{1F6FF}]/u';
        $clean_text = preg_replace($regexTransport, '', $clean_text);
        // Match Miscellaneous Symbols
        $regexMisc = '/[\x{2600}-\x{26FF}]/u';
        $clean_text = preg_replace($regexMisc, '', $clean_text);
        // Match Dingbats
        $regexDingbats = '/[\x{2700}-\x{27BF}]/u';
        $clean_text = preg_replace($regexDingbats, '', $clean_text);
        return $clean_text;
    }

}